package com.java.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author jl
 * Created on 2020/9/12
 * 订单确认页的数据
 */
public class OrderConfirmVo {

    /**
     * 收货地址ums_member_receive_address表
     */
    @Setter
    @Getter
    private List<MemberAddressVo> addressVos;
    /**
     * 所有选中的购物项
     */
    @Setter @Getter
    private List<OrderItemVo> items;
    /**
     * 积分
     */
    @Setter @Getter
    private Integer integration;

    /**
     * 订单防止重复提交token
     */
    @Setter @Getter
    private String orderToken;

    @Getter @Setter
    Map<Long,Boolean> stocks;

    public Integer getCount() {
        Integer i = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
               i += item.getCount();
            }
        }
        return i;
    }

    /**
     * 订单总额
     */
//    private BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /**
     * 应付价格
     */
//    private BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}

